package com.example.zxq_server.whbgy.fragpack;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.cocolove2.library_cocodialog.dialogs.NormalCocoDialog;
import com.example.administrator.idocment.LocalFileTool;
import com.example.administrator.idocment.msgpack.modelpack.DocModel;
import com.example.zxq_server.whbgy.R;
import com.example.zxq_server.whbgy.adpterpack.ExcelFileAdapter;
import com.example.zxq_server.whbgy.adpterpack.IExcelCallBack;

import java.util.List;

/**
 * Created by zxq_Server on 2017/9/9.
 */
public class PhoneFileFragment extends Fragment implements IExcelCallBack, LocalFileTool.IReadCallBack<List<DocModel>>
{




    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        return inflater.inflate(R.layout.frag_phonefile,null);
    }

     private IFileCallBack iFileCallBack;

    public void setiFileCallBack(IFileCallBack iFileCallBack) {
        this.iFileCallBack = iFileCallBack;
    }

    private RecyclerView phoneRecyle;

    NormalCocoDialog dialog;
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
          phoneRecyle= view.findViewById(R.id.myRecyle);
          LocalFileTool.readFile(LocalFileTool.docFlag,getActivity(),this);
          dialog= new NormalCocoDialog(getActivity());

        dialog.setMessage("正在扫描本地Excel文件,请稍后……");
          dialog.show();
    }



    @Override
    public void excelPath(String localPath) {
        if(iFileCallBack!=null)
            iFileCallBack.setFilePath(localPath);
    }

    @Override
    public void callBack(List<DocModel> localPath) {
        ExcelFileAdapter excelFileAdapter=new ExcelFileAdapter(localPath,getContext());
        excelFileAdapter.setiExcelCallBack(this);
        phoneRecyle.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false));
        phoneRecyle.setAdapter(excelFileAdapter);
        dialog.dismiss();
    }
}
